<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.css"/>
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.theme.default.css"/>
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/js/libs/jquery.treetable.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class='form-group'>
                <label class='col-md-4 control-label'>项目名称：</label>
                <div class='col-md-8'>
                    <input class="form-control" placeholder="项目名称" name="name" id="name"
                           data-bv-notempty='true' data-bv-notempty-message='项目名称 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>项目描述：</label>
                <div class='col-md-8'>
                    <textarea class="form-control" placeholder="项目描述" name="description" id="description"
                              data-bv-notempty='true' data-bv-notempty-message='项目描述 不能为空'></textarea>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>负责人：</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='executorId' id='executorId' data-bv-notempty='true' data-bv-notempty-message='负责人 不能为空'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='负责人' type='text'
                           name='executorName' id='executorName'data-bv-notempty='true' data-bv-notempty-message='负责人 不能为空'
                           readonly>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>成员：</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='participantId' id='participantId' data-bv-notempty='true' data-bv-notempty-message='成员 不能为空'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='成员' type='text'
                           name='participantName' id='participantName' data-bv-notempty='true' data-bv-notempty-message='成员 不能为空'
                           readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields( 'user', 'user', '用户', true, true, 'participantId:id', 'participantName:nickname')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>项目等级：<i title="项目紧急程度" class="layui-icon layui-icon-tips" style="font-size: 10px; color: #737373;"></i>  </label>
                <div class='col-md-8'>
                    <select class="form-control input-sm selectpicker show-tick" name="grade" id="grade"
                            title="项目等级" data-live-search="true"></select>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>截止日期：</label>
                <div class='col-md-8'>
                    <input class='form-control' placeholder='截止日期' type='text' name='deadline' id='deadline'
                           data-bv-notempty='true' data-bv-notempty-message='截止日期 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>项目状态:</label>
                <div class='col-md-8'>
                    <select class="form-control input-sm selectpicker show-tick" name="status" id="status"
                            title="项目状态" data-live-search="true"></select>
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" type="submit" onclick="save()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript">
        $(function () {
            $('#form').bootstrapValidator();
        });
        $("#executorId").val(getCurrentUserId);
        $("#executorName").val(getCurrentUserName)
        layui.use(['layer', 'laydate'], function () {
            var layer = layui.layer;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#deadline',
                done: function(value, date, endDate){
                    // console.log(value); //得到日期生成的值，如：2017-08-18
                    // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                    // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                    if ($("#form").data('bootstrapValidator')) {
                        $("#form").data('bootstrapValidator').resetForm();
                    }
                }
            });
        });

        var grade = showDictSelect('grade', 'dept_level', '', '1');
        var status = showDictSelect('status', 'task_status', '', '0');
        function save() {
            $('#form').bootstrapValidator();
            var bootstrapValidator = $("#form").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (!bootstrapValidator.isValid()) {
                return;
            }

            var formdata = $("#form").serializeObject();

            $.ajax({
                type: 'post',
                url: '/project/',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(formdata),
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg("保存成功", {shift: -1, time: 1000}, function () {
                            parent.location.reload();//关闭iFrame
                        });
                    } else {
                        layer.msg("保存失败：" + data.message, {shift: -1, time: 1000});
                    }
                }
            });
        }

</script>
</body>
</html>
